package com.stsdai.manager.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.stsdai.common.pojo.StsdaiResult;
import com.stsdai.manager.pojo.Item;
import com.stsdai.manager.service.ItemService;

@Controller
@RequestMapping("item")
public class ItemController {

	@Autowired
	private ItemService itemService;

	// type: "POST",
	// url: "/rest/item",
	/**
	 * 新增商品
	 * 
	 * @param item
	 * @param desc
	 */
	@RequestMapping(method = RequestMethod.POST)
	@ResponseBody // 必须要加
	public void saveItem(Item item, String desc) {
		/*item.setPrice(item.getPrice()/100);*/
		this.itemService.saveItem(item, desc);
	}
	/**
	 * 分页查询商品
	 * @param page
	 * @param rows
	 * @return
	 */
	//url:'/rest/item',method:'get',pageSize:30,
	@RequestMapping(method = RequestMethod.GET)
	@ResponseBody
	public StsdaiResult<Item> queryItemByPage(@RequestParam(value = "page",defaultValue = "1" )Integer page,
			@RequestParam(value = "rows",defaultValue = "30") Integer rows){
		StsdaiResult<Item> stsdaiResult = this.itemService.queryItemByPage(page, rows);
				return stsdaiResult;
		
	}
}
